import pyautogui
import time
import threading

# 定义一个全局变量来控制连点是否进行
is_clicking = False


def click_loop():
    global is_clicking
    while True:
        if is_clicking:
            pyautogui.click(button='left')
            # 随机等待一段时间，模拟不定时连点
            # 这里设置等待时间在0.01到0.1秒之间
            time.sleep(time.uniform(0.01, 0.1))
        else:
            time.sleep(0.1)


# 创建一个线程来运行连点循环
thread = threading.Thread(target=click_loop)
thread.start()

try:
    while True:
        print("循环开始")
        mouse_info = pyautogui.mouseInfo()
        print(f"mouse_info:{mouse_info}")


        if pyautogui.rightClick():
            is_clicking = not is_clicking
            # 等待0.2秒，防止过于频繁地检测右键点击
            time.sleep(0.2)
except KeyboardInterrupt:
    print("程序已停止")
